package com.example.shop.controller;

import com.example.shop.entity.Article;
import com.example.shop.service.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ArticleController
 * @Description TODO
 * @Author 萍
 * @Date 2025/3/26 10:16
 */

@Controller
@RequestMapping("/article")
@Tag(name = "ArticleController", description = "对Article操作的接口")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 通过ID查询单条数据
     *
     * @param articleId 主键
     * @return 实例对象
     */
    @GetMapping("/{articleId}")
    @Operation(summary = "通过ID查询单条数据", description = "通过ID查询单条数据")
    @ResponseBody
    public Article queryById(@PathVariable("articleId") Integer articleId) {
        System.out.println(articleId );
        System.out.println(articleService.queryById(articleId));
        return articleService.queryById(articleId);
    }

    /**
     * 新增数据
     *
     * @param article 实例对象
     * @return 实例对象
     */
    @PostMapping
    public Article insert(@RequestBody Article article) {
        return articleService.insert(article);
    }

    /**
     * 修改数据
     *
     * @param article 实例对象
     * @return 实例对象
     */
    @PutMapping
    public Article update(@RequestBody Article article) {
        return articleService.update(article);
    }

    /**
     * 通过主键删除数据
     *
     * @param articleId 主键
     * @return 是否成功
     */
    @DeleteMapping("/{articleId}")
    public boolean deleteById(@PathVariable("articleId") Integer articleId) {
        return articleService.deleteById(articleId);
    }
    @GetMapping("/helloArticle")
    public String hello() {
        return "Article";
    }
}
